/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bpmlab.shift.dao;

import bpmlab.shift.dao.service.CardapioDAO;
import bpmlab.shift.dao.service.GenericDAO;
import bpmlab.shift.entity.Cardapio;
import java.util.List;
import javax.persistence.EntityManager;

/**
 *
 * @author Mikael Lima
 */
public class CardapioDAOJpa implements CardapioDAO {

    private final GenericDAO<Cardapio> dao = DAOFactory.criarGenericDAO(Cardapio.class);

    @Override
    public void salvar(Cardapio o) throws DAOException {
        dao.salvar(o);
    }

    @Override
    public void excluir(Cardapio o) throws DAOException {
        dao.excluir(o);
    }

    @Override
    public Cardapio obter(Object id) {
        return dao.obter(id);
    }

    @Override
    public List<Cardapio> obterTodos() {
        return dao.obterTodos();
    }

    @Override
    public List<Cardapio> obterTodosComItens() {
        EntityManager manager = JpaUtil.getEntityManager();
        String jpql = "select distinct c from Cardapio c left join fetch c.itens";
        return manager.createQuery(jpql, Cardapio.class).getResultList();
    }
    
}
